import request from 'src/axios'

/**
 * @description 分页查询角色列表
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const pageRole = (params: object) => {
  return request.get('/system/role/page', { params })
}

/**
 * @description 查询所有角色
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const listRole = (params?: object) => {
  return request.get('/system/role/list', { params })
}

/**
 * @description 查看角色信息
 * @param { String } id 角色主键
 * @returns Promise
 */
export const viewRole = (id: string) => {
  return request.get('/system/role', { params: { id } })
}

/**
 * @description 新增角色
 * @param { Object } data 新增数据
 * @returns Promise
 */
export const saveRole = (data: object) => {
  return request.post('/system/role', data)
}

/**
 * @description 修改角色
 * @param { Object } data 修改数据
 * @returns Promise
 */
export const updateRole = (data: object) => {
  return request.put('/system/role', data)
}

/**
 * @description 删除角色
 * @param { Array<string> } ids 角色主键数组
 * @returns Promise
 */
export const deleteRole = (ids: Array<string>) => {
  return request.delete('/system/role', { data: ids })
}

/**
 * @description 启用角色
 * @param { String } id 角色主键
 * @returns Promise
 */
export const enableRole = (id: string) => {
  return request.put('/system/role/enable', { id })
}

/**
 * @description 禁用角色
 * @param { String } id 角色主键
 * @returns Promise
 */
export const disableRole = (id: string) => {
  return request.put('/system/role/disable', { id })
}

/**
 * @description 查询角色已授予权限
 * @param { String } id 角色主键
 * @returns Promise
 */
export const listCheckedPermission = (id: string) => {
  return request.get('/system/role/permission', { params: { id } })
}

/**
 * @description 授予角色权限
 * @param { Object } data 授权数据
 * @returns Promise
 */
export const grantPermission = (data: object) => {
  return request.post('/system/role/grant/permission', data)
}

/**
 * @description 查询未分配用户
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const listUnCheckeAccount = (params: object) => {
  return request.get('/system/role/account/uncheck', { params })
}

/**
 * @description 查询已分配用户
 * @param { Object } params 查询参数
 * @returns Promise
 */
export const listCheckedAccount = (params: object) => {
  return request.get('/system/role/account/checked', { params })
}

/**
 * @description 分配用户
 * @param { Object } data 分配数据
 * @returns Promise
 */
export const grantAccount = (data: object) => {
  return request.post('/system/role/grant/account', data)
}

/**
 * @description 释放用户
 * @param { Array<string> } ids 主键数组
 * @returns Promise
 */
export const releaseAccount = (ids: Array<string>) => {
  return request.delete('/system/role/grant/account', { data: ids })
}
